#ifndef PLAYLISTCLIENT_H
#define PLAYLISTCLIENT_H

#include "../Common/Socket.h"
#include "../Common/Playlist.h"
#include "../Common/Song.h"
#include "../Common/Runnable.h"
#include "../Common/Observable.h"

#include <fstream>
#include <sstream>
#include <iostream>

//size of message packet
#define MESSAGE_SIZE 128
//size of packet for data from a file
#define DATA_SIZE 1024
//size of a playlist packet from server to client
#define PLAYLIST_SIZE 4096

/*-----------------------------------------------------------------------------------------------
--
--	CLASS: PlaylistClient
--
--	Date: March 25, 2010
--
--	REVISIONS (Date and Description):
--
--	DESIGNER: Brad Paugh
--
--	PROGRAMMER: Brad Paugh
--
--  INTERFACE: class PlaylistClient : public Runnable, public Observable
--
--  RETURNS: N/A
--
--	NOTES: Program class for the Playlist Client. Responsible for receiving playlist updates
--         from the Playlist server such as new songs added and votes for each song. In turn,
--         this Playlist client may also add songs to its own playlist but must send this
--         information to the server so that all other connected clients may update their own
--         playlists.
--
-----------------------------------------------------------------------------------------------*/
class PlaylistClient : public Runnable, public Observable
{
	public:
		PlaylistClient();
		void connectToServer(std::string ip, int port);
		void sendFile(std::string path);
		void sendVote(std::string filename);
		std::string outputPlaylist();
		inline Playlist* getPlaylist(){ return &playlist_; }
        inline double getUploadProgress() { return uploadProgress; }
		void run();
        void close();

                enum EventCodes { UploadStarted, UploadProgressChanged, UploadFinished };

	private:
		Socket sock;
		Playlist playlist_;
		std::string filename;
		std::string path;
                double uploadProgress;
		
		std::string extractFilename(std::string path);
		void storePlaylist(std::string buffer);
		static void threadStart(void* param);
		void receiveThread();
};

#endif
